import React from 'react';
import fx from './utils/fx';

const config = {
  avg_duration: {
    cases: [{
      case: value => (value <= 60 * 60),
      text: '日内波动型(超短线交易)',
    }, {
      case: value => (value <= 24 * 60 * 60),
      text: '日内波动型交易员',
    }, {
      case: value => (value <= 7 * 24 * 60 * 60),
      text: '日间趋势型交易员(短线)',
    }],
    default: '趋势型交易员(中长线)',
  },
  avg_daily_volume: {
    cases: [{
      case: value => (value <= 100000),
      text: '操盘资金量小, 属于新手交易员',
    }, {
      case: value => (value <= 1000000),
      text: '操盘资金量中等, 属于初级交易员',
    }, {
      case: value => (value <= 5000000),
      text: '操盘资金量较大, 属于高级交易员',
    }, {
      case: value => (value <= 50000000),
      text: '操盘资金很大, 属于优秀交易员',
    }],
    default: '操盘资金巨大，可能属于团队共用对冲账号',
  },
  position_efficiency: {
    cases: [{
      case: value => (value >= 0.4),
      text: '优秀',
    }, {
      case: value => (value >= 0.3),
      text: '还不错',
    }, {
      case: value => (value >= 0.2),
      text: '一般',
    }],
    default: '低',
  },
  potential_risk: {
    cases: [{
      case: value => (value >= -0.003),
      text: '低',
    }, {
      case: value => (value >= -0.0035),
      text: '较低',
    }, {
      case: value => (value >= -0.004),
      text: '较高',
    }],
    default: '高',
  },
  risk_over_pnl: {
    cases: [{
      case: value => (value >= -1),
      text: '小',
    }, {
      case: value => (value >= -2),
      text: '较小',
    }, {
      case: value => (value >= -5),
      text: '较大',
    }],
    default: '大',
  },
  pnl_efficiency: {
    cases: [{
      case: value => (value <= 0),
      text: '很差',
    }, {
      case: value => (value <= 100),
      text: '优秀',
    }, {
      case: value => (value <= 250),
      text: '较好',
    }, {
      case: value => (value <= 500),
      text: '一般',
    }],
    default: '需要提高',
  },
  risk_control: {
    cases: [{
      case: value => (value <= 20),
      text: '是一个大问题',
    }, {
      case: value => (value <= 40),
      text: '需要提高',
    }, {
      case: value => (value <= 60),
      text: '一般',
    }, {
      case: value => (value <= 70),
      text: '不错',
    }],
    default: '很成熟',
  },
  profitability: {
    cases: [{
      case: value => (value <= 20),
      text: '表现较差',
    }, {
      case: value => (value <= 40),
      text: '有待提高',
    }, {
      case: value => (value <= 60),
      text: '表现一般',
    }, {
      case: value => (value <= 70),
      text: '还不错',
    }],
    default: '表现优秀',
  },
};

export const val = (v, decimal = 2) => {
  return (<em>{v == undefined ? 0 : fx.formatNumber(v, decimal)}</em>);
};

export default function Comments({ features, name }) {
  const value = features[name];
  const cfg = config[name];
  if (cfg === undefined) {
    return (<b />);
  }
  let text = cfg.default;

  for (let i = 0; i < cfg.cases.length; i++) {
    const item = cfg.cases[i];
    if (item.case(value)) {
      text = item.text;
      break;
    }
  }

  return (
    <b>{text}</b>
  );
}
